<?php

namespace App\Api\Sms;

class SmsClient
{
//    修改这里的通道名称,调用对应的接口
    private $channelName = "Feige";
//    private $channelName = "Shlianlu";
    public $client = "";
//根据'smsType' => [1 => '验证码', 2 => '通知', 3 => '营销'],分开配置的
    private $smsType = 1;

    public function __construct($smsType = 1)
    {
        $this->smsType = $smsType;
        $this->client = $this->loadChannel();
    }

    /**
     * 加载通道,每个通道必须实现以下方法
     * @return null
     */
    public function loadChannel($channelName = null)
    {
        $obj = null;
        if (!empty($channelName)) {
            $this->channelName = $channelName;
        }
        $channelName = 'App\Api\Sms\\' . $this->channelName;
        if (class_exists($channelName)) {
            $obj = new $channelName($this->smsType);
        }
        return $obj;
    }

    /**
     * sendSmsByTpl($tplId, $phone, $param = [])
     * * sendSms($phone, $content)
     * * addTpl($tplName, $tplType, $tplContent)
     * * editTpl($tplId, $tplName, $tplContent)
     * * delTpl($tpl_id)
     * * queryTpl($tpl_id)
     * * getBalance()
     * @return mixed
     */
    public function __call($name, $arguments)
    {
        return call_user_func_array([$this->client, $name], $arguments);
    }
}
